/**
 * Copyright (C) 2018-2020
 * All rights reserved, Designed By www.yixiang.co
 * 注意：
 * 本软件为www.yixiang.co开发研制，未经购买不得使用
 * 购买后可获得全部源代码（禁止转卖、分享、上传到码云、github等开源平台）
 * 一经发现盗用、分享等行为，将追究法律责任，后果自负
 */
package co.yixiang.modules.product.service.impl;

import co.yixiang.common.service.impl.BaseServiceImpl;
import co.yixiang.modules.product.domain.YxTestQuestionType;
import co.yixiang.modules.product.service.YxTestQuestionTypeService;
import co.yixiang.modules.product.service.dto.YxTestQuestionTypeDto;
import co.yixiang.modules.product.service.dto.YxTestQuestionTypeQueryCriteria;
import co.yixiang.modules.product.service.mapper.YxTestQuestionTypeMapper;
import lombok.AllArgsConstructor;
import co.yixiang.dozer.service.IGenerator;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import co.yixiang.common.utils.QueryHelpPlus;
import co.yixiang.utils.ValidationUtil;
import co.yixiang.utils.FileUtil;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import cn.hutool.core.lang.Snowflake;
import cn.hutool.core.util.IdUtil;
// 默认不使用缓存
//import org.springframework.cache.annotation.CacheConfig;
//import org.springframework.cache.annotation.CacheEvict;
//import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import java.util.List;
import java.util.Map;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import co.yixiang.domain.PageResult;
/**
 * @author lsh
 * @date 2022-05-09
 */
@Service
@AllArgsConstructor
//@CacheConfig(cacheNames = "yxTestQuestionType")
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
public class YxTestQuestionTypeServiceImpl extends BaseServiceImpl<YxTestQuestionTypeMapper, YxTestQuestionType> implements YxTestQuestionTypeService {

	private final IGenerator generator;

	@Override
	//@Cacheable
	public PageResult<YxTestQuestionTypeDto> queryAll(YxTestQuestionTypeQueryCriteria criteria, Pageable pageable) {
		getPage(pageable);
		PageInfo<YxTestQuestionType> page = new PageInfo<>(queryAll(criteria));
		return generator.convertPageInfo(page,YxTestQuestionTypeDto.class);
	}


	@Override
	//@Cacheable
	public List<YxTestQuestionType> queryAll(YxTestQuestionTypeQueryCriteria criteria){
		return baseMapper.selectList(QueryHelpPlus.getPredicate(YxTestQuestionType.class, criteria));
	}


	@Override
	public void download(List<YxTestQuestionTypeDto> all, HttpServletResponse response) throws IOException {
		List<Map<String, Object>> list = new ArrayList<>();
		for (YxTestQuestionTypeDto yxTestQuestionType : all) {
			Map<String,Object> map = new LinkedHashMap<>();
			map.put("类型名称", yxTestQuestionType.getQuestionName());
			map.put("等级ID", yxTestQuestionType.getLevelId());
			map.put("添加时间", yxTestQuestionType.getCreateTime());
			map.put(" updateTime",  yxTestQuestionType.getUpdateTime());
			map.put("是否删除", yxTestQuestionType.getIsDel());
			map.put("总分", yxTestQuestionType.getTotalScore());
			map.put("排序", yxTestQuestionType.getSort());
			list.add(map);
		}
		FileUtil.downloadExcel(list, response);
	}
}
